package phan.connection;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.io.File;

/**
 *
 * @author bailleurs services
 */
public class RetailleImage {
    //public final static String IMAGE_TYPE_JPEG = "jpeg";

//public final static String IMAGE_TYPE_GIF = "gif";

//public final static String IMAGE_TYPE_PNG = "png";
public RetailleImage(){

}
public RetailleImage(String PathImage) throws IOException{
    String pictureName = PathImage;
// Mettez la dimension de la capture finale ici

// L'image originale
BufferedImage photo = ImageIO.read(new File(PathImage));

System.out.print("chieu rong: "+photo.getWidth());
System.out.print("chieu cao: "+photo.getHeight());
//Dimension finalDim = new Dimension(160, 120);
Dimension finalDim = new Dimension(129, photo.getHeight()*129/photo.getWidth());

// L'image redimensionnée

BufferedImage bufFinal = new BufferedImage(finalDim.width,
                finalDim.height, BufferedImage.TYPE_INT_RGB);

// Redimensionnement de l'image
Graphics2D g = (Graphics2D) bufFinal.getGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(photo, 0, 0, finalDim.width, finalDim.height, null);
g.dispose();

// Ecriture de l'image sur le disque
try {
    ImageIO.write(bufFinal, "jpg", new File(pictureName));
} catch (IOException e) {
    e.printStackTrace();
}





}
}
